﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;

public partial class Controls_History : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateControls();
        }
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        Redirector.RedirectIfNotAuthenticated();
    }

    private void PopulateControls()
    {
        int howManyPages = 0;
        string firstPageUrl = Link.ToCustomerDetails("1"); ;
        string pagerFormat = Link.ToCustomerDetails("{0}"); ;
        string page = Request.QueryString["Page"] ?? "1";
        HttpContext context = HttpContext.Current;
        if (context != null)
        {
            string userName = context.User.Identity.Name;
            RepHistory.DataSource = OrderDetail.GetByUserName(userName, page, out howManyPages);
            RepHistory.DataBind();

            pagerTop.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, false);
            pagerBottom.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true);
        }
    }
}